home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / para.lha / para / texnfo-upd.el < prev    next >
Text File  |  1991-04-18  |  66KB  |  1,763 lines

  1. ;;;; texnfo-upd.el
  2.  
  3. ;;; Texinfo mode utilities for updating nodes and menus in Texinfo files.
  4.  
  5. ;;; Version 2.04    17 April 1991
  6. ;;; Robert J. Chassell      
  7. ;;; Please send bug reports to:  bob@ai.mit.edu
  8.  
  9. ;;; Copyright 1989, 1990, 1991 Free Software Foundation
  10.  
  11. ;;; Known bug: update commands fail to ignore @ignore.
  12.  
  13.  
  14. ;;; This file is part of GNU Emacs.
  15.  
  16. ;; GNU Emacs is free software; you can redistribute it and/or modify
  17. ;; it under the terms of the GNU General Public License as published by
  18. ;; the Free Software Foundation; either version 1, or (at your option)
  19. ;; any later version.
  20.  
  21. ;; GNU Emacs is distributed in the hope that it will be useful,
  22. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. ;; GNU General Public License for more details.
  25.  
  26. ;; You should have received a copy of the GNU General Public License
  27. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  28. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  29.  
  30.  
  31. ;;; Summary: how to use the updating commands
  32.  
  33. ; The node and menu updating functions automatically
  34.  
  35. ;   * insert missing `@node' lines,
  36. ;   * insert the `Next', `Previous' and `Up' pointers of a node,
  37. ;   * insert or update the menu for a section, 
  38. ;   * create a master menu for a Texinfo source file.
  39. ;
  40. ; Passed an argument, the `texinfo-update-node' and
  41. ; `texinfo-make-menu' functions do their jobs in the region.
  42. ;
  43. ; In brief, the functions for creating or updating nodes and menus, are:
  44. ;     texinfo-update-node (&optional region-p)            
  45. ;     texinfo-every-node-update ()                        
  46. ;     texinfo-sequential-node-update (&optional region-p)
  47. ;     texinfo-make-menu (&optional region-p)              
  48. ;     texinfo-all-menus-update ()                         
  49. ;     texinfo-master-menu ()
  50. ;
  51. ;     texinfo-insert-node-lines  (&optional title-p)
  52. ;     texinfo-indent-menu-description (column &optional region-p)
  53.  
  54. ; The `texinfo-column-for-description' variable specifies the column to
  55. ; which menu descriptions are indented. 
  56.  
  57. ; Texinfo file structure
  58. ; ----------------------
  59.  
  60. ; To use the updating commands, you must structure your Texinfo file
  61. ; hierarchically.  Each `@node' line, with the exception of the top
  62. ; node, must be accompanied by some kind of section line, such as an
  63. ; `@chapter' or `@section' line.  Each node-line/section-line
  64. ; combination must look like this:
  65.  
  66. ;      @node    Lists and Tables, Cross References, Structuring, Top
  67. ;      @comment node-name,        next,             previous,    up
  68. ;      @chapter Making Lists and Tables
  69.  
  70. ; or like this (without the `@comment' line):
  71.  
  72. ;      @node    Lists and Tables, Cross References, Structuring, Top
  73. ;      @chapter Making Lists and Tables
  74.  
  75. ; If the file has a `top' node, it must be called `top' or `Top' and
  76. ; be the first node in the file.
  77.  
  78.  
  79. ;;; The update node functions described in detail
  80.  
  81. ; The `texinfo-update-node' function without an argument inserts
  82. ; the correct next, previous and up pointers for the node in which
  83. ; point is located (i.e., for the node preceding point).
  84.  
  85. ; With an argument, the `texinfo-update-node' function inserts the
  86. ; correct next, previous and up pointers for the nodes inside the
  87. ; region.
  88.  
  89. ; It does not matter whether the  `@node' line has pre-existing
  90. ; `Next', `Previous', or `Up' pointers in it.  They are removed.
  91.  
  92. ; The `texinfo-every-node-update' function runs `texinfo-update-node'
  93. ; on the whole buffer.
  94.  
  95. ; The `texinfo-update-node' function inserts the immediately following
  96. ; and preceding node into the `Next' or `Previous' pointers regardless
  97. ; of their hierarchical level.  This is only useful for certain kinds
  98. ; of text, like a novel, which you go through sequentially.  
  99.  
  100.  
  101. ;;; The menu making functions described in detail
  102.  
  103. ; The `texinfo-make-menu' function without an argument creates or
  104. ; updates a menu for the section encompassing the node that follows
  105. ; point.  With an argument, it makes or updates menus for the nodes
  106. ; within or part of the marked region.
  107.  
  108. ; Whenever an existing menu is updated, the descriptions from
  109. ; that menu are incorporated into the new menu.  This is done by copying
  110. ; descriptions from the existing menu to the entries in the new menu
  111. ; that have the same node names.  If the node names are different, the
  112. ; descriptions are not copied to the new menu.
  113.  
  114. ; Menu entries that refer to other Info files are removed since they
  115. ; are not a node within current buffer.  This is a deficiency.
  116.  
  117. ; The `texinfo-all-menus-update' function runs `texinfo-make-menu'
  118. ; on the whole buffer.
  119.  
  120. ; The `texinfo-master-menu' function creates an extended menu located
  121. ; after the top node.  (The file must have a top node.)  The function
  122. ; first updates all the regular menus in the buffer (incorporating the
  123. ; descriptions from pre-existing menus), and then constructs a master
  124. ; menu that includes every entry from every other menu.  (However, the
  125. ; function cannot update an already existing master menu; if one
  126. ; exists, it must be removed before calling the function.)
  127.  
  128. ; The `texinfo-indent-menu-description' function indents every
  129. ; description in the menu following point, to the specified column.
  130. ; Non-nil argument (prefix, if interactive) means indent every
  131. ; description in every menu in the region.  This function does not
  132. ; indent second and subsequent lines of a multi-line description.
  133.  
  134. ; The `texinfo-insert-node-lines' function inserts `@node' before the
  135. ; `@chapter', `@section', and such like lines of a region in a Texinfo
  136. ; file where the `@node' lines are missing.
  137. ; With a non-nil argument (prefix, if interactive), the function not
  138. ; only inserts `@node' lines but also inserts the chapter or section
  139. ; titles as the names of the corresponding nodes; and inserts titles
  140. ; as node names in pre-existing `@node' lines that lack names.
  141. ; Since node names should be more concise than section or chapter
  142. ; titles, node names so inserted will need to be edited manually.
  143.  
  144.  
  145. ;;; The menu making functions
  146.  
  147. (defun texinfo-make-menu (&optional region-p)
  148.   "Without any prefix argument, make or update a menu.
  149. Make the menu for the section enclosing the node found following point.
  150.  
  151. Non-nil argument (prefix, if interactive) means make or update menus
  152. for nodes within or part of the marked region.
  153.  
  154. Whenever a menu exists, and is being updated, the descriptions that
  155. are associated with node names in the pre-existing menu are
  156. incorporated into the new menu.  Otherwise, the nodes' section titles
  157. are inserted as descriptions."
  158.   
  159.   (interactive "P")
  160.   (if (not region-p)
  161.       (let ((level (texinfo-hierarchic-level)))
  162.         (texinfo-make-one-menu level)
  163.         (message "Done...updated the menu.  You may save the buffer."))
  164.     ;; else
  165.     (message "Making or updating menus... ")
  166.     (let ((beginning (region-beginning))
  167.       (region-end (region-end))
  168.           (level (progn         ; find section type following point
  169.                    (goto-char (region-beginning))
  170.                    (texinfo-hierarchic-level))))
  171.       (if (= region-end beginning)
  172.           (error "Please mark a region!"))
  173.       (save-excursion
  174.         (save-restriction
  175.           (widen)
  176.           
  177.           (while  (texinfo-find-lower-level-node level region-end)
  178.             (setq level (texinfo-hierarchic-level)) ; new, lower level
  179.             (texinfo-make-one-menu level))
  180.           
  181.           (while (and (< (point) region-end)
  182.                       (texinfo-find-higher-level-node level region-end))
  183.             (setq level (texinfo-hierarchic-level))
  184.             (while (texinfo-find-lower-level-node level region-end)
  185.               (setq level (texinfo-hierarchic-level)) ; new, lower level
  186.               (texinfo-make-one-menu level))))))
  187.     (message "Done...updated menus.  You may save the buffer.")))
  188.  
  189. (defun texinfo-make-one-menu (level)
  190.   "Make a menu of all the appropriate nodes in this section.
  191. `Appropriate nodes' are those associated with sections that are 
  192. at the level specified by LEVEL.  Point is left at the end of menu."
  193.   (let*
  194.       ((case-fold-search t)
  195.        (beginning
  196.     (save-excursion
  197.       (goto-char (texinfo-update-menu-region-beginning level))
  198.       (end-of-line)
  199.       (point)))
  200.        (end (texinfo-update-menu-region-end level))
  201.        (first (texinfo-menu-first-node beginning end))
  202.        (node-name (progn
  203.                     (goto-char beginning)
  204.                     (texinfo-copy-node-name)))
  205.        (new-menu-list (texinfo-make-menu-list beginning end level)))
  206.     (if (texinfo-old-menu-p beginning first)
  207.         (progn
  208.           (texinfo-incorporate-descriptions new-menu-list)
  209.           (texinfo-delete-old-menu beginning first)))
  210.     (texinfo-insert-menu new-menu-list node-name)))
  211.  
  212. (defun texinfo-all-menus-update (&optional update-all-nodes-p)
  213.   "Update every regular menu in a Texinfo file.
  214. Update pre-existing master menu, if there is one.
  215.  
  216. If called with a non-nil argument, this function first updates all the
  217. nodes in the buffer before updating the menus."
  218.   (interactive "P")
  219.   (let (master-menu-p)
  220.     (save-excursion
  221.       (mark-whole-buffer)
  222.       (message "Checking for a master menu... ")
  223.       (save-excursion
  224.         (if (re-search-forward texinfo-master-menu-header nil t)
  225.             ;; Remove detailed master menu listing
  226.             (progn
  227.               (setq master-menu-p t)
  228.               (goto-char (match-beginning 0))
  229.               (let ((end-of-detailed-menu-descriptions
  230.                      (save-excursion     ; beginning of end menu line
  231.                        (goto-char (texinfo-menu-end))
  232.                        (beginning-of-line) (forward-char -1)
  233.                        (point))))
  234.                 (delete-region (point) end-of-detailed-menu-descriptions)))))
  235.       
  236.       (if update-all-nodes-p
  237.           (progn
  238.             (message "First updating all nodes... ")
  239.             (sleep-for 2)
  240.             (mark-whole-buffer)
  241.             (texinfo-update-node t)))
  242.       
  243.       (message "Updating all menus... ")        
  244.       (sleep-for 2)
  245.       (mark-whole-buffer)
  246.       (texinfo-make-menu t)
  247.       
  248.       (if master-menu-p
  249.           (message "Updating the master menu ... ")
  250.         (sleep-for 2)
  251.         (texinfo-master-menu nil)))
  252.     
  253.     (message "Done...updated all the menus.  You may save the buffer.")))
  254.  
  255. (defun texinfo-find-lower-level-node (level region-end)
  256.   "Search forward from point for node at any level lower than LEVEL.
  257. Search is limited to the end of the marked region, REGION-END, 
  258. and to the end of the menu region for the level.
  259.  
  260. Return t if the node is found, else nil.  Leave point at the beginning
  261. of the node if one is found; else do not move point."
  262.  
  263.   (if (and (< (point) region-end)
  264.            (re-search-forward
  265.             (concat
  266.              "\\(^@node\\).*\n"         ; match node line
  267.              "\\(\\(\\(^@c\\).*\n\\)"   ; match comment line, if any
  268.              "\\|"                      ; or
  269.              "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
  270.              (eval (cdr (assoc level texinfo-update-menu-lower-regexps))))
  271.             ;; the next higher level node marks the end of this
  272.             ;; section, and no lower level node will be found beyond
  273.             ;; this position even if region-end is farther off
  274.             (texinfo-update-menu-region-end level) 
  275.             t))
  276.       (goto-char (match-beginning 1))))
  277.  
  278. (defun texinfo-find-higher-level-node (level region-end)
  279.   "Search forward from point for node at any higher level than argument LEVEL.
  280. Search is limited to the end of the marked region, REGION-END.
  281.  
  282. Return t if the node is found, else nil.  Leave point at the beginning
  283. of the node if one is found; else do not move point."
  284.  
  285.   (if (and (< (point) region-end)
  286.            (re-search-forward
  287.             (concat
  288.              "\\(^@node\\).*\n"         ; match node line
  289.              "\\(\\(\\(^@c\\).*\n\\)"   ; match comment line, if any
  290.              "\\|"                      ; or
  291.              "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
  292.              (eval                      ; (won't ever find a `top' node)
  293.               (cdr (assoc level texinfo-update-menu-higher-regexps))))
  294.             nil
  295.             t))
  296.       (goto-char (match-beginning 1))))
  297.  
  298.  
  299. ;;; Making the list of new menu entries
  300.  
  301. (defun texinfo-make-menu-list (beginning end level)
  302.   "Make a list of node names and their descriptions.
  303. Point is left at the end of the menu region, but the menu is not inserted.
  304.  
  305. First argument is position from which to start making menu list; 
  306. second argument is end of region in which to try to locate entries;
  307. third argument is the level of the nodes that are the entries.
  308.  
  309. Node names and descriptions are dotted pairs of strings.  Each pair is
  310. an element of the list.  If the description does not exist, the
  311. element consists only of the node name."
  312.   (goto-char beginning)
  313.   (let (new-menu-list)
  314.     (while (texinfo-menu-locate-entry-p level end)
  315.       (setq new-menu-list 
  316.             (cons (cons 
  317.                    (texinfo-copy-node-name)
  318.                    (texinfo-copy-section-title))
  319.                   new-menu-list)))
  320.     (reverse new-menu-list)))
  321.  
  322. (defun texinfo-menu-locate-entry-p (level search-end)
  323.   "Find a node that will be part of menu for this section.
  324. First argument is a string such as \"section\" specifying the general
  325. hierarchical level of the menu; second argument is a postion
  326. specifying the end of the search.
  327.  
  328. The function returns t if the node is found, else nil.  It searches
  329. forward from point, and leaves point at the beginning of the node.
  330.  
  331. The function finds entries of the same type.  Thus `subsections' and
  332. `unnumberedsubsecs' will appear in the same menu."
  333.   (if (re-search-forward
  334.        (concat
  335.         "\\(^@node\\).*\n"              ; match node line
  336.         "\\(\\(\\(^@c\\).*\n\\)"        ; match comment line, if any
  337.         "\\|"                           ; or
  338.         "\\(^@ifinfo[ ]*\n\\)\\)?"      ; ifinfo line, if any
  339.         (eval
  340.          (cdr (assoc level texinfo-update-menu-same-level-regexps))))
  341.        search-end
  342.        t)
  343.       (goto-char (match-beginning 1))))
  344.  
  345. (defun texinfo-copy-node-name ()
  346.   "Return the node name as a string.
  347.  
  348. Start with point at the beginning of the node line; copy the text
  349. after the node command up to the first comma on the line, if any, and
  350. return the text as a string.  Leaves point at the beginning of the
  351. line.  If there is no node name, returns an empty string."
  352.   
  353.   (save-excursion
  354.     (buffer-substring
  355.      (progn (forward-word 1)              ; skip over node command
  356.             (skip-chars-forward " \t")    ; and over spaces
  357.             (point))
  358.      (if (search-forward
  359.           ","
  360.           (save-excursion (end-of-line) (point)) t) ; bound search
  361.          (1- (point))
  362.        (end-of-line) (point)))))
  363.  
  364. (defun texinfo-copy-section-title ()
  365.   "Return the title of the section as a string.
  366. The title is used as a description line in the menu when one does not
  367. already exist.
  368.  
  369. Move point to the beginning of the appropriate section line by going
  370. to the start of the text matched by last regexp searched for, which
  371. must have been done by `texinfo-menu-locate-entry-p'."
  372.  
  373.   ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
  374.   ;; instead of using `match-beginning'; such a variation would be
  375.   ;; more general, but would waste information already collected
  376.  
  377.   (goto-char (match-beginning 7))       ; match section name 
  378.  
  379.   (buffer-substring
  380.    (progn (forward-word 1)              ; skip over section type
  381.           (skip-chars-forward " \t")    ; and over spaces
  382.           (point))
  383.    (progn (end-of-line) (point))))
  384.  
  385.  
  386. ;;; Handling the old menu
  387.  
  388. (defun texinfo-old-menu-p (beginning first)
  389.   "Move point to the beginning of the menu for this section, if any.
  390. Otherwise move point to the end of the first node of this section.
  391. Return t if a menu is found, nil otherwise.
  392.  
  393. First argument is the position of the beginning of the section in which
  394. the menu will be located; second argument is the position of the first
  395. node within the section.
  396.  
  397. If no menu is found, the function inserts two newlines just before the
  398. end of the section, and leaves point there where a menu ought to be."
  399.   (goto-char beginning)
  400.   (if (not (re-search-forward "^@menu" first 'goto-end))
  401.       (progn (insert "\n\n") (forward-line -2) nil)
  402.     t))
  403.  
  404. (defun texinfo-incorporate-descriptions (new-menu-list)
  405.   "Copy the old menu line descriptions that exist to the new menu.
  406.  
  407. Point must be at beginning of old menu.
  408.  
  409. If the node-name of the new menu entry cannot be found in the old
  410. menu, use the new section title for the description, but if the
  411. node-name of the new menu is found in the old menu, replace the
  412. section title with the old description, whatever it may be.
  413.  
  414. For this function, the new menu is a list made up of lists of dotted
  415. pairs in which the first element of the pair is the node name and the
  416. second element the description. The new menu is changed destructively.
  417. The old menu is the menu as it appears in the texinfo file."
  418.   
  419.   (let ((new-menu-list-pointer new-menu-list)
  420.         (end-of-menu (texinfo-menu-end)))
  421.     (while new-menu-list
  422.       (save-excursion                   ; keep point at beginning of menu 
  423.         (if (search-forward
  424.              (concat "\* "              ; so only menu entries are found
  425.                      (car (car new-menu-list))
  426.                      ":")               ; so only complete entries are found
  427.              end-of-menu
  428.              t) 
  429.             (setcdr (car new-menu-list) 
  430.                     (texinfo-menu-copy-old-description end-of-menu))))
  431.       (setq new-menu-list (cdr new-menu-list))) 
  432.     (setq new-menu-list new-menu-list-pointer)))
  433.  
  434. (defun texinfo-menu-copy-old-description (end-of-menu)
  435.   "Return description field of old menu line as string.
  436. Point must be located just after the node name.  Point left before description.
  437. Single argument, END-OF-MENU, is position limiting search."
  438.   (skip-chars-forward "[:.,\t\n ]+")
  439.   ;; don't copy a carriage return at line beginning with asterisk!
  440.   ;; do copy a description that begins with an `@'!
  441.   (if (and (looking-at "\\(\\w+\\|@\\)")    
  442.            (not (looking-at "\\(^\\* \\|^@end menu\\)")))  
  443.       (buffer-substring
  444.        (point)
  445.        (save-excursion
  446.          (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t)
  447.          (forward-line -1)
  448.          (end-of-line)                  ; go to end of last description line
  449.          (point)))
  450.     ""))
  451.  
  452. (defun texinfo-menu-end ()
  453.   "Return position of end of menu. Does not change location of point.
  454. Signal an error if not end of menu."
  455.   (save-excursion
  456.     (if (re-search-forward "^@end menu" nil t)
  457.         (point)
  458.       (error "Menu does not have an end."))))
  459.  
  460. (defun texinfo-delete-old-menu (beginning first)
  461.   "Delete the old menu.  Point must be in or after menu.
  462. First argument is position of the beginning of the section in which
  463. the menu will be located; second argument is the position of the first
  464. node within the section."
  465.   ;; No third arg to search, so error if search fails.
  466.   (re-search-backward "^@menu" beginning)
  467.   (delete-region (point)
  468.                  (save-excursion
  469.                    (re-search-forward "^@end menu" first)
  470.                    (point))))
  471.  
  472.  
  473. ;;; Inserting new menu
  474.  
  475. ;; try 32, but perhaps 24 is better
  476. (defvar texinfo-column-for-description 32
  477.   "*Column at which descriptions start in a Texinfo menu.")
  478.  
  479. (defun texinfo-insert-menu (menu-list node-name)
  480.   "Insert formatted menu at point.
  481. Indents the first line of the description, if any, to the value of
  482. texinfo-column-for-description.
  483.  
  484. MENU-LIST has form:
  485.  
  486.     \(\(\"node-name1\" . \"description\"\) 
  487.     \(\"node-name\" . \"description\"\) ... \)
  488.  
  489. However, there does not need to be a description field."
  490.   
  491.   (insert "@menu\n")
  492.   (while menu-list
  493.     (if (cdr (car menu-list))       ; menu-list has description entry
  494.         (progn
  495.           (insert 
  496.            (format "* %s::" (car (car menu-list)))) ; node-name entry
  497.           (indent-to texinfo-column-for-description 2)
  498.           (insert 
  499.            (format "%s\n" (cdr (car menu-list)))))  ; description entry
  500.         ;; else menu-list lacks description entry
  501.       (insert
  502.        (format "* %s::\n" (car (car menu-list)))))  ; node-name entry
  503.     (setq menu-list (cdr menu-list)))
  504.   (insert "@end menu")
  505.   (message
  506.    "Updated \"%s\" level menu following node: %s ... "
  507.    level node-name))
  508.  
  509.  
  510. ;;; Handling description indentation
  511.  
  512. ; Since the make-menu functions indent descriptions, these functions
  513. ; are useful primarily for indenting a single menu specially.
  514.  
  515. (defun texinfo-indent-menu-description (column &optional region-p)
  516.   "Indent every description in menu following point to COLUMN.  
  517. Non-nil argument (prefix, if interactive) means indent every
  518. description in every menu in the region.  Does not indent second and
  519. subsequent lines of a multi-line description."
  520.   
  521.   (interactive
  522.    "nIndent menu descriptions to (column number): \nP")
  523.   (save-excursion
  524.     (save-restriction
  525.       (widen)
  526.       (if (not region-p)
  527.           (progn
  528.             (re-search-forward "^@menu")
  529.             (texinfo-menu-indent-description column)
  530.             (message
  531.              "Indented descriptions in menu.  You may save the buffer."))
  532.         ;;else
  533.         (message "Indenting every menu description in region... ")
  534.         (goto-char (region-beginning))
  535.         (while (and (< (point) (region-end))
  536.                     (texinfo-locate-menu-p))
  537.           (forward-line 1)
  538.           (texinfo-menu-indent-description column))
  539.         (message "Indenting done.  You may save the buffer.")))))
  540.  
  541. (defun texinfo-menu-indent-description (to-column-number)
  542.   "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
  543. Start with point just after the word `menu' in the `@menu' line and
  544. leave point on the line before the `@end menu' line.  Does not indent
  545. second and subsequent lines of a multi-line description."
  546.   (let* ((beginning-of-next-line (point)))
  547.     (while (< beginning-of-next-line
  548.               (save-excursion     ; beginning of end menu line
  549.                 (goto-char (texinfo-menu-end))
  550.                 (beginning-of-line)
  551.                 (point)))
  552.       (if (search-forward "::" (texinfo-menu-end) t)
  553.           (progn
  554.             (let ((beginning-white-space (point)))
  555.               (skip-chars-forward " \t")  ; skip over spaces
  556.               (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
  557.                   (progn
  558.                     ;; remove pre-existing indentation
  559.                     (delete-region beginning-white-space (point))
  560.                     (indent-to-column to-column-number))))))
  561.       ;; position point at beginning of next line
  562.       (forward-line 1)                  
  563.       (setq beginning-of-next-line (point)))))
  564.  
  565.  
  566. ;;; Making the master menu
  567.  
  568. (defun texinfo-master-menu (update-all-nodes-menus-p)
  569.   "Make a master menu for a whole Texinfo file.
  570. Non-nil argument (prefix, if interactive) means first update all
  571. existing nodes and menus.  Remove pre-existing master menu, if there is one.
  572.  
  573. This function creates a master menu that follows the top node.  The
  574. master menu includes every entry from all the other menus.  It
  575. replaces any existing ordinary menu that follows the top node.
  576.  
  577. If called with a non-nil argument, this function first updates all the
  578. menus in the buffer (incorporating descriptions from pre-existing
  579. menus) before it constructs the master menu.
  580.  
  581. The function removes the detailed part of an already existing master
  582. menu.  This action depends on the pre-exisitng master menu using the
  583. standard `texinfo-master-menu-header'.
  584.  
  585. The master menu has the following format, which is adapted from the
  586. recommendation in the Texinfo Manual:
  587.  
  588.    * The first part contains the major nodes in the Texinfo file: the
  589.      nodes for the chapters, chapter-like sections, and the major
  590.      appendices.  This includes the indices, so long as they are in
  591.      chapter-like sections, such as unnumbered sections.
  592.  
  593.    * The second and subsequent parts contain a listing of the other,
  594.      lower level menus, in order.  This way, an inquirer can go
  595.      directly to a particular node if he or she is searching for
  596.      specific information.
  597.  
  598. Each of the menus in the detailed node listing is introduced by the
  599. title of the section containing the menu."
  600.  
  601.   (interactive "P")
  602.   (widen)
  603.   (goto-char (point-min))
  604.  
  605.   ;; Move point to location after `top'.
  606.   (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
  607.       (error "This buffer needs a Top node!"))
  608.  
  609.   (let ((first-chapter                  
  610.          (save-excursion (re-search-forward "^@node") (point))))
  611.     (if (re-search-forward texinfo-master-menu-header first-chapter t)
  612.         ;; Remove detailed master menu listing
  613.         (progn
  614.            (goto-char (match-beginning 0))
  615.           (let ((end-of-detailed-menu-descriptions
  616.                  (save-excursion     ; beginning of end menu line
  617.                    (goto-char (texinfo-menu-end))
  618.                    (beginning-of-line) (forward-char -1)
  619.                    (point))))
  620.             (delete-region (point) end-of-detailed-menu-descriptions)))))
  621.  
  622.   (if update-all-nodes-menus-p
  623.       (progn
  624.         (message "Making a master menu...first updating all nodes... ")
  625.         (sleep-for 2)
  626.         (mark-whole-buffer)
  627.         (texinfo-update-node t)
  628.  
  629.         (message "Updating all menus... ")        
  630.         (sleep-for 2)
  631.         (mark-whole-buffer)
  632.         (texinfo-make-menu t)))
  633.  
  634.   (message "Now making the master menu... ")
  635.   (sleep-for 2)
  636.   (goto-char (point-min))
  637.   (texinfo-insert-master-menu-list
  638.    (texinfo-master-menu-list))
  639.  
  640.   ;; Remove extra newlines that texinfo-insert-master-menu-list
  641.   ;; may have inserted.
  642.  
  643.   (save-excursion
  644.     (goto-char (point-min))
  645.     
  646.     (re-search-forward texinfo-master-menu-header)
  647.     (goto-char (match-beginning 0))
  648.     (insert "\n")
  649.     (delete-blank-lines)
  650.     
  651.     (re-search-backward "^@menu")
  652.     (forward-line -1)
  653.     (delete-blank-lines)
  654.     
  655.     (re-search-forward "^@end menu")
  656.     (forward-line 1)
  657.     (delete-blank-lines))
  658.  
  659.   (message "Done...completed making master menu.  You may save the buffer."))
  660.  
  661. (defun texinfo-master-menu-list ()
  662.   "Return a list of menu entries and header lines for the master menu.
  663.  
  664. Start with the menu for chapters and indices and then find each
  665. following menu and the title of the node preceding that menu.
  666.  
  667. The master menu list has this form:
  668.  
  669.     \(\(\(... \"entry-1-2\"  \"entry-1\"\) \"title-1\"\)
  670.       \(\(... \"entry-2-2\"  \"entry-2-1\"\) \"title-2\"\)
  671.       ...\)
  672.  
  673. However, there does not need to be a title field."
  674.  
  675.   (let (master-menu-list)
  676.     (while (texinfo-locate-menu-p)
  677.       (setq master-menu-list 
  678.             (cons (list
  679.                    (texinfo-copy-menu)
  680.                    (texinfo-copy-menu-title))
  681.                   master-menu-list)))
  682.     (reverse master-menu-list)))
  683.  
  684. (defun texinfo-insert-master-menu-list (master-menu-list)
  685.   "Format and insert the master menu in the current buffer."
  686.   (goto-char (point-min))
  687.   (re-search-forward "^@menu")
  688.   (beginning-of-line)
  689.   (delete-region (point)        ; buffer must have ordinary top menu
  690.                  (save-excursion
  691.                    (re-search-forward "^@end menu")
  692.                    (point)))
  693.  
  694.   (save-excursion                       ; leave point at beginning of menu
  695.   ;; Handle top of menu
  696.   (insert "\n@menu\n")
  697.   ;; Insert chapter menu entries
  698.   (setq this-very-menu-list (reverse (car (car master-menu-list))))
  699.   ;;; Tell user what is going on.
  700.   (message "Inserting chapter menu entry: %s ... " this-very-menu-list)
  701.   (while this-very-menu-list
  702.     (insert "* " (car this-very-menu-list) "\n")
  703.     (setq this-very-menu-list (cdr this-very-menu-list)))
  704.   
  705.   (setq master-menu-list (cdr master-menu-list))
  706.  
  707.   (insert texinfo-master-menu-header)
  708.   
  709.   ;; Now, insert all the other menus
  710.  
  711.   ;; The menu master-menu-list has a form like this:
  712.   ;; ((("beta"  "alpha") "title-A")
  713.   ;;  (("delta" "gamma") "title-B"))
  714.  
  715.   (while master-menu-list
  716.  
  717.     (message
  718.      "Inserting menu for %s .... " (car (cdr (car master-menu-list))))
  719.     ;; insert title of menu section
  720.     (insert "\n" (car (cdr (car master-menu-list))) "\n\n")
  721.  
  722.     ;; insert each menu entry
  723.     (setq this-very-menu-list (reverse (car (car master-menu-list))))
  724.     (while this-very-menu-list
  725.       (insert "* " (car this-very-menu-list) "\n")
  726.       (setq this-very-menu-list (cdr this-very-menu-list)))
  727.     
  728.     (setq master-menu-list (cdr master-menu-list)))
  729.   
  730.   ;; Finish menu
  731.   (insert "@end menu\n\n")))
  732.  
  733. (defvar texinfo-master-menu-header
  734.   "\n --- The Detailed Node Listing ---\n"
  735.   "String inserted before lower level entries in Texinfo master menu.
  736. It comes after the chapter-level menu entries.")
  737.  
  738. (defun texinfo-locate-menu-p ()
  739.   "Find the next menu in the texinfo file.
  740. If found, leave point after word `menu' on the `@menu' line, and return t.
  741. If a menu is not found, do not move point and return nil."
  742.   (re-search-forward "\\(^@menu\\)" nil t))
  743.  
  744. (defun texinfo-copy-menu-title  ()
  745.   "Return the title of the section preceding the menu as a string.
  746. If such a title cannot be found, return an empty string.  Do not move
  747. point."
  748.   (save-excursion
  749.     (if (re-search-backward
  750.          (concat
  751.           "\\(^@node\\).*\n"            ; match node line
  752.           "\\(\\(\\(^@c\\).*\n\\)"      ; match comment line, if any
  753.           "\\|"                         ; or
  754.           "\\(^@ifinfo[ ]*\n\\)\\)?"    ; ifinfo line, if any
  755.           (eval
  756.            (cdr
  757.             (assoc (texinfo-hierarchic-level)
  758.                    texinfo-update-menu-higher-regexps))))
  759.          nil
  760.          t)
  761.         (texinfo-copy-section-title)
  762.       " ")))
  763.  
  764. (defun texinfo-copy-menu ()
  765.   "Return the entries of an existing menu as a list.
  766. Start with point just after the word `menu' in the `@menu' line
  767. and leave point on the line before the `@end menu' line."
  768.   (let* (this-menu-list
  769.          (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
  770.          (last-entry (save-excursion      ; position of beginning of
  771.                                           ; last `* ' entry
  772.                       (goto-char end-of-menu)
  773.                       (re-search-backward "^\* ") ; handle multi-line desc.
  774.                       (point))))
  775.     (while (< (point) last-entry)
  776.       (if (re-search-forward  "^\* " end-of-menu t)
  777.           (progn
  778.             (setq this-menu-list
  779.                   (cons
  780.                    (buffer-substring 
  781.                     (point)
  782.                     ;; copy multi-line descriptions
  783.                     (save-excursion
  784.                       (re-search-forward "\\(^\* \\|^@e\\)" nil t)
  785.                       (- (point) 3)))
  786.                    this-menu-list)))))
  787.     this-menu-list))
  788.  
  789.  
  790. ;;; Determining the hierarchical level in the texinfo file
  791.  
  792. (defun texinfo-specific-section-type () 
  793.   "Return the specific type of next section, as a string.
  794. For example, \"unnumberedsubsec\".  Return \"top\" for top node.
  795.  
  796. Searches forward for a section.  Hence, point must be before the
  797. section whose type will be found.  Does not move point.  Signal an
  798. error if the node is not the top node and a section is not found."
  799.   (save-excursion
  800.     (cond
  801.      ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
  802. ;;; Following search limit by cph but causes a bug
  803. ;;;             (save-excursion
  804. ;;;               (end-of-line)
  805. ;;;               (point))
  806.                          nil
  807.              t)
  808.       "top")
  809.      ((re-search-forward texinfo-section-types-regexp nil t)
  810.       (buffer-substring (progn (beginning-of-line) ; copy its name
  811.                                (1+ (point)))
  812.                         (progn (forward-word 1)
  813.                                (point))))
  814.      (t
  815.       (error
  816.        "texinfo-specific-section-type: Chapter or section not found.")))))
  817.  
  818. (defun texinfo-hierarchic-level ()
  819.   "Return the general hierarchal level of the next node in a texinfo file.
  820. Thus, a subheading or appendixsubsec is of type subsection."
  821.   (cdr (assoc
  822.         (texinfo-specific-section-type)
  823.         texinfo-section-to-generic-alist)))
  824.  
  825.  
  826. ;;; Locating the major positions
  827.  
  828. (defun texinfo-update-menu-region-beginning (level)  
  829.   "Locate beginning of higher level section this section is within.
  830. Return position of the beginning of the node line; do not move point.
  831. Thus, if this level is subsection, searches backwards for section node.
  832. Only argument is a string of the general type of section."
  833.   
  834.   (cond
  835.    ((or (string-equal "top" level)
  836.     (string-equal "chapter" level))
  837.     (save-excursion
  838.       (goto-char (point-min))
  839.       (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t)
  840.       (beginning-of-line)
  841.       (point)))
  842.    (t
  843.     (save-excursion
  844.       (re-search-backward
  845.        (concat
  846.         "\\(^@node\\).*\n"              ; match node line
  847.         "\\(\\(\\(^@c\\).*\n\\)"        ; match comment line, if any
  848.         "\\|"                           ; or
  849.         "\\(^@ifinfo[ ]*\n\\)\\)?"      ; ifinfo line, if any
  850.         (eval
  851.          (cdr (assoc level texinfo-update-menu-higher-regexps))))
  852.        nil
  853.        'goto-beginning)
  854.       (point)))))
  855.  
  856. (defun texinfo-update-menu-region-end (level)  
  857.   "Locate end of higher level section this section is within.
  858. Return position; do not move point.  Thus, if this level is a
  859. subsection, find the node for the section this subsection is within.
  860. If level is top or chapter, returns end of file.  Only argument is a
  861. string of the general type of section."
  862.  
  863.   (save-excursion
  864.     (if (re-search-forward
  865.          (concat
  866.           "\\(^@node\\).*\n"            ; match node line
  867.           "\\(\\(\\(^@c\\).*\n\\)"      ; match comment line, if any
  868.           "\\|"                         ; or
  869.           "\\(^@ifinfo[ ]*\n\\)\\)?"    ; ifinfo line, if any
  870.           (eval
  871.            (cdr (assoc level texinfo-update-menu-higher-regexps))))
  872.          nil
  873.          'goto-end)
  874.         (match-beginning 1)
  875.       (point-max))))
  876.  
  877. (defun texinfo-menu-first-node (beginning end)
  878.   "Locate first node of the section the menu will be placed in.  
  879. Return position; do not move point.
  880. The menu will be located just before this position.  
  881.  
  882. First argument is the position of the beginning of the section in
  883. which the menu will be located; second argument is the position of the
  884. end of that region; it limits the search."
  885.   
  886.   (save-excursion
  887.     (goto-char beginning)
  888.     (forward-line 1)
  889.     (re-search-forward "^@node" end t)
  890.     (beginning-of-line)
  891.     (point)))
  892.  
  893.  
  894. ;;; Alists and regular expressions for defining hierarchical levels
  895.  
  896. (defvar texinfo-section-to-generic-alist
  897.   '(("top" . "top")
  898.  
  899.     ("chapter" . "chapter")
  900.     ("unnumbered" . "chapter")
  901.     ("majorheading" . "chapter")
  902.     ("chapheading" . "chapter")
  903.     ("appendix" . "chapter")
  904.     
  905.     ("section" . "section")
  906.     ("unnumberedsec" . "section")
  907.     ("heading" . "section")
  908.     ("appendixsec" . "section")
  909.     
  910.     ("subsection" . "subsection")
  911.     ("unnumberedsubsec" . "subsection")
  912.     ("subheading" . "subsection")
  913.     ("appendixsubsec" . "subsection")
  914.     
  915.     ("subsubsection" . "subsubsection")
  916.     ("unnumberedsubsubsec" . "subsubsection")
  917.     ("subsubheading" . "subsubsection")
  918.     ("appendixsubsubsec" . "subsubsection"))
  919.   "*An alist of specific and corresponding generic Texinfo section types.
  920. The keys are strings specifying specific types of section; the values
  921. are strings of their corresponding general types.")
  922.  
  923. (defvar texinfo-section-types-regexp
  924.   "^@\\(chapter \\|sect\\|sub\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
  925.   "Regexp matching chapter, section, other headings (but not the top node).")
  926.  
  927. (defvar texinfo-chapter-level-regexp 
  928.   "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
  929.   "Regular expression matching just the Texinfo chapter level headings.")
  930.  
  931. (defvar texinfo-section-level-regexp 
  932.   "section\\|unnumberedsec\\|heading \\|appendixsec"
  933.   "Regular expression matching just the Texinfo section level headings.")
  934.  
  935. (defvar texinfo-subsection-level-regexp 
  936.   "subsection\\|unnumberedsubsec\\|subheading\\|appendixsubsec"
  937.   "Regular expression matching just the Texinfo subsection level headings.")
  938.  
  939. (defvar texinfo-subsubsection-level-regexp
  940.   "subsubsection\\|unnumberedsubsubsec\\|subsubheading\\|appendixsubsubsec"
  941.   "Regular expression matching just the Texinfo subsubsection level headings.")
  942.  
  943. (defvar texinfo-update-menu-same-level-regexps
  944.   '(("top" . "top[ \t]+")
  945.     ("chapter" . 
  946.      (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp "\\)[ \t]*"))
  947.     ("section" . 
  948.      (concat "\\(^@\\)\\(" texinfo-section-level-regexp "\\)[ \t]*"))
  949.     ("subsection" .  
  950.      (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp "\\)[ \t]+"))
  951.     ("subsubsection" . 
  952.      (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp "\\)[ \t]+")))
  953.   "*Regexps for searching for same level sections in a Texinfo file.
  954. The keys are strings specifying the general hierarchical level in the
  955. document; the values are regular expressions.")
  956.  
  957. (defvar texinfo-update-menu-higher-regexps
  958.   '(("top" . "^@node [ \t]*DIR") 
  959.     ("chapter" . "^@node [ \t]*top[ \t]*\\(,\\|$\\)")
  960.     ("section" .
  961.      (concat 
  962.       "\\(^@\\("
  963.       texinfo-chapter-level-regexp
  964.       "\\)[ \t]*\\)"))
  965.     ("subsection" .
  966.      (concat 
  967.       "\\(^@\\("
  968.       texinfo-section-level-regexp
  969.       "\\|"
  970.       texinfo-chapter-level-regexp
  971.       "\\)[ \t]*\\)"))
  972.     ("subsubsection" .
  973.      (concat 
  974.       "\\(^@\\("
  975.       texinfo-subsection-level-regexp
  976.       "\\|"
  977.       texinfo-section-level-regexp
  978.       "\\|"
  979.       texinfo-chapter-level-regexp
  980.       "\\)[ \t]*\\)")))
  981.   "*Regexps for searching for higher level sections in a Texinfo file.
  982. The keys are strings specifying the general hierarchical level in the
  983. document; the values are regular expressions.")
  984.  
  985. (defvar texinfo-update-menu-lower-regexps
  986.   '(("top" . 
  987.      (concat 
  988.       "\\(^@\\("
  989.       texinfo-chapter-level-regexp
  990.       "\\|"
  991.       texinfo-section-level-regexp
  992.       "\\|"
  993.       texinfo-subsection-level-regexp
  994.       "\\|"
  995.       texinfo-subsubsection-level-regexp
  996.       "\\)[ \t]*\\)"))
  997.     ("chapter" . 
  998.      (concat 
  999.       "\\(^@\\("
  1000.       texinfo-section-level-regexp
  1001.       "\\|"
  1002.       texinfo-subsection-level-regexp
  1003.       "\\|"
  1004.       texinfo-subsubsection-level-regexp
  1005.       "\\)[ \t]*\\)"))
  1006.     ("section" .
  1007.      (concat 
  1008.       "\\(^@\\("
  1009.       texinfo-subsection-level-regexp
  1010.       "\\|"
  1011.       texinfo-subsubsection-level-regexp
  1012.       "\\)[ \t]+\\)"))
  1013.     ("subsection" .
  1014.      (concat 
  1015.       "\\(^@\\("
  1016.       texinfo-subsubsection-level-regexp
  1017.       "\\)[ \t]+\\)"))
  1018.     ("subsubsection" . "nothing lower"))
  1019.   "*Regexps for searching for lower level sections in a Texinfo file.
  1020. The keys are strings specifying the general hierarchical level in the
  1021. document; the values are regular expressions.")
  1022.  
  1023.  
  1024. ;;; Updating a node
  1025.  
  1026. (defun texinfo-update-node (&optional region-p)
  1027.   "Without any prefix argument, update the node in which point is located.
  1028. Non-nil argument (prefix, if interactive) means update the nodes in the
  1029. marked region.
  1030.  
  1031. The functions for creating or updating nodes and menus, and their
  1032. keybindings, are:
  1033.  
  1034.     texinfo-update-node (&optional region-p)    \\[texinfo-update-node]
  1035.     texinfo-every-node-update ()                \\[texinfo-every-node-update]
  1036.     texinfo-sequential-node-update (&optional region-p)
  1037.  
  1038.     texinfo-make-menu (&optional region-p)      \\[texinfo-make-menu]
  1039.     texinfo-all-menus-update ()                 \\[texinfo-all-menus-update]
  1040.     texinfo-master-menu ()
  1041.  
  1042.     texinfo-indent-menu-description (column &optional region-p)
  1043.  
  1044. The `texinfo-column-for-description' variable specifies the column to
  1045. which menu descriptions are indented. Its default value is 32."
  1046.   
  1047.   (interactive "P")
  1048.   (if (not region-p)
  1049.       (let ((auto-fill-hook nil)) ; update a single node
  1050.         (if (not (re-search-backward "^@node" (point-min) t))
  1051.             (error "Node line not found before this position."))
  1052.         (texinfo-update-the-node)
  1053.         (message "Done...updated the node.  You may save the buffer."))
  1054.     ;; else
  1055.     (let ((auto-fill-hook nil)
  1056.           (beginning (region-beginning))
  1057.       (end (region-end)))
  1058.       (if (= end beginning)
  1059.           (error "Please mark a region!"))
  1060.       (save-restriction
  1061.     (narrow-to-region beginning end)
  1062.     (goto-char beginning)
  1063.         (push-mark)
  1064.     (while (re-search-forward "^@node" (point-max) t)
  1065.           (beginning-of-line)            
  1066.           (texinfo-update-the-node))
  1067.         (message "Done...updated nodes in region.  You may save the buffer.")))))
  1068.  
  1069. (defun texinfo-every-node-update ()
  1070.   "Update every node in a Texinfo file."
  1071.   (interactive)
  1072.   (save-excursion
  1073.     (mark-whole-buffer)
  1074.     (texinfo-update-node t)
  1075.     (message "Done...updated every node.       You may save the buffer.")))
  1076.  
  1077. (defun texinfo-update-the-node ()
  1078.   "Update one node.  Point must be at the beginning of node line.  
  1079. Leave point at the end of the node line."
  1080.   (texinfo-check-for-node-name)
  1081.   (texinfo-delete-existing-pointers)
  1082.   (message "Updating node: %s ... " (texinfo-copy-node-name))
  1083.   (save-restriction
  1084.     (widen)
  1085.     (let*
  1086.         ((case-fold-search t)
  1087.          (level (texinfo-hierarchic-level))
  1088.          (beginning (texinfo-update-menu-region-beginning level))
  1089.          (end (texinfo-update-menu-region-end level)))
  1090.       (if (string-equal level "top")
  1091.           (texinfo-top-pointer-case)
  1092.         ;; else
  1093.         (texinfo-insert-pointer beginning end level 'next)
  1094.         (texinfo-insert-pointer beginning end level 'previous)
  1095.         (texinfo-insert-pointer beginning end level 'up)
  1096.         (texinfo-clean-up-node-line)))))
  1097.  
  1098. (defun texinfo-top-pointer-case ()
  1099.   "Insert pointers in the Top node.  This is a special case.
  1100.  
  1101. The `Next' pointer is a pointer to a chapter or section at a lower
  1102. hierarchical level in the file.  The `Previous' and `Up' pointers are
  1103. to `(dir)'.  Point must be at the beginning of the node line, and is
  1104. left at the end of the node line."
  1105.  
  1106.   (texinfo-clean-up-node-line)
  1107.   (insert ", " 
  1108.           (save-excursion
  1109.             ;; There may be an @chapter or other such command between
  1110.             ;; the top node line and the next node line, as a title
  1111.             ;; for an `ifinfo' section. This @chapter command must
  1112.             ;; must be skipped.  So the procedure is to search for
  1113.             ;; the next `@node' line, and then copy its name.
  1114.             (if (re-search-forward "^@node" nil t)
  1115.                 (progn
  1116.                   (beginning-of-line)
  1117.                   (texinfo-copy-node-name))
  1118.               " "))
  1119.           ", (dir), (dir)"))
  1120.  
  1121. (defun texinfo-check-for-node-name ()
  1122.   "Determine whether the node has a node name.  Prompt for one if not.
  1123. Point must be at beginning of node line.  Does not move point."
  1124.   (save-excursion
  1125.     (forward-word 1)                    ; skip over node command
  1126.     (skip-chars-forward " \t")          ; and over spaces
  1127.     (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what info looks for
  1128.                                         ; alternatively, use "[a-zA-Z]+"
  1129.         (let ((node-name (read-from-minibuffer "Node name: ")))
  1130.           (insert " " node-name)))))
  1131.  
  1132. (defun texinfo-delete-existing-pointers ()
  1133.   "Delete `Next', `Previous', and `Up' pointers.  
  1134. Starts from the current position of the cursor, and searches forward
  1135. on the line for a comma and if one is found, deletes the rest of the
  1136. line, including the comma.  Leaves point at beginning of line."
  1137.   (if (search-forward "," (save-excursion (end-of-line) (point)) t)
  1138.       (progn
  1139.         (goto-char (1- (point)))
  1140.         (kill-line nil)))
  1141.   (beginning-of-line))
  1142.  
  1143. (defun texinfo-find-pointer (beginning end level direction)
  1144.   "Move point to section associated with next, previous, or up pointer.
  1145. Return type of pointer (either 'normal or 'no-pointer).
  1146.  
  1147. The first and second arguments bound the search for a pointer to the
  1148. beginning and end, respectively, of the enclosing higher level
  1149. section.  The third argument is a string specifying the general kind
  1150. of section such as \"chapter\ or \"section\".  When looking for the
  1151. `Next' pointer, the section found will be at the same hierarchical
  1152. level in the Texinfo file; when looking for the `Previous' pointer,
  1153. the section found will be at the same or higher hierarchical level in
  1154. the Texinfo file; when looking for the `Up' pointer, the section found
  1155. will be at some level higher in the Texinfo file.  The fourth argument
  1156. \(one of 'next, 'previous, or 'up\) specifies whether to find the
  1157. `Next', `Previous', or `Up' pointer."
  1158.  
  1159.   (cond ((eq direction 'next)
  1160.          (forward-line 3)             ; skip over current node
  1161.          (if (re-search-forward
  1162.               (eval
  1163.                (cdr (assoc level texinfo-update-menu-same-level-regexps)))
  1164.               end
  1165.               t)
  1166.              'normal
  1167.            'no-pointer))
  1168.         ((eq direction 'previous)
  1169.          (if (re-search-backward
  1170.               (concat
  1171.                "\\("
  1172.                (eval
  1173.                 (cdr (assoc level texinfo-update-menu-same-level-regexps)))
  1174.                "\\|"
  1175.                (eval
  1176.                 (cdr (assoc level texinfo-update-menu-higher-regexps)))
  1177.                "\\)")
  1178.               beginning
  1179.               t)
  1180.              'normal
  1181.            'no-pointer))
  1182.         ((eq direction 'up)
  1183.          (if (re-search-backward
  1184.              (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
  1185.               (save-excursion
  1186.                 (goto-char beginning)
  1187.                 (beginning-of-line)
  1188.                 (point))
  1189.               t)
  1190.              'normal
  1191.            'no-pointer))
  1192.         (t
  1193.          (error "texinfo-find-pointer: lack proper arguments"))))
  1194.  
  1195. (defun texinfo-pointer-name (kind)
  1196.   "Return the node name preceding the section command.
  1197. The argument is the kind of section, either normal or no-pointer."
  1198.   (let (name)
  1199.     (cond ((eq kind 'normal)
  1200.            (end-of-line)                ; this handles prev node top case
  1201.            (re-search-backward          ; when point is already 
  1202.             "^@node"                    ; at the beginning of @node line
  1203.             (save-excursion (forward-line -3))
  1204.             t)
  1205.            (setq name (texinfo-copy-node-name)))
  1206.       ((eq kind 'no-pointer)
  1207.        (setq name " ")))    ; put a blank in the pointer slot
  1208.     name))
  1209.  
  1210. (defun texinfo-insert-pointer (beginning end level direction)
  1211.   "Insert the `Next', `Previous' or `Up' node name at point.
  1212. Move point forward.  
  1213.  
  1214. The first and second arguments bound the search for a pointer to the
  1215. beginning and end, respectively, of the enclosing higher level
  1216. section.  The third argument is the hierarchical level of the Texinfo
  1217. file, a string such as \"section\".  The fourth argument is direction
  1218. towards which the pointer is directed, one of `next, `previous, or
  1219. 'up."
  1220.  
  1221.   (end-of-line)
  1222.   (insert
  1223.    ", "
  1224.    (save-excursion
  1225.      (texinfo-pointer-name
  1226.       (texinfo-find-pointer beginning end level direction)))))
  1227.  
  1228. (defun texinfo-clean-up-node-line ()
  1229.   "Remove extra commas, if any, at end of node line."
  1230.   (end-of-line)
  1231.   (skip-chars-backward ", ")
  1232.   (delete-region (point) (save-excursion (end-of-line) (point))))
  1233.  
  1234.  
  1235. ;;; Updating nodes sequentially
  1236. ; These sequential update functions insert `Next' or `Previous'
  1237. ; pointers that point to the following or preceding nodes even if they
  1238. ; are at higher or lower hierarchical levels.  This means that if a
  1239. ; section contains one or more subsections, the section's `Next'
  1240. ; pointer will point to the subsection and not the following section.
  1241. ; (The subsection to which `Next' points will most likely be the first
  1242. ; item on the section's menu.)
  1243.  
  1244. (defun texinfo-sequential-node-update (&optional region-p)
  1245.   "Update one node (or many) in a Texinfo file with sequential pointers.
  1246.  
  1247. This function causes the `Next' or `Previous' pointer to point to the
  1248. immediately preceding or following node, even if it is at a higher or
  1249. lower hierarchical level in the document.  Continually pressing `n' or
  1250. `p' takes you straight through the file.
  1251.  
  1252. Without any prefix argument, update the node in which point is located.
  1253. Non-nil argument (prefix, if interactive) means update the nodes in the
  1254. marked region.
  1255.  
  1256. This command makes it awkward to navigate among sections and
  1257. subsections; it should be used only for those documents that are meant
  1258. to be read like a novel rather than a reference, and for which the
  1259. Info `g*' command is inadequate."
  1260.   
  1261.   (interactive "P")
  1262.   (if (not region-p)
  1263.       (let ((auto-fill-hook nil))   ; update a single node
  1264.         (if (not (re-search-backward "^@node" (point-min) t))
  1265.             (error "Node line not found before this position."))
  1266.         (texinfo-sequentially-update-the-node)
  1267.         (message 
  1268.          "Done...sequentially updated the node .  You may save the buffer."))
  1269.     ;; else
  1270.     (let ((auto-fill-hook nil)
  1271.           (beginning (region-beginning))
  1272.           (end (region-end)))
  1273.       (if (= end beginning)
  1274.           (error "Please mark a region!"))
  1275.       (save-restriction
  1276.         (narrow-to-region beginning end)
  1277.         (goto-char beginning)
  1278.         (push-mark)
  1279.         (while (re-search-forward "^@node" (point-max) t)
  1280.           (beginning-of-line)            
  1281.           (texinfo-sequentially-update-the-node))
  1282.         (message 
  1283.          "Done...updated the nodes in sequence.  You may save the buffer.")))))
  1284.  
  1285. (defun texinfo-sequentially-update-the-node ()
  1286.   "Update one node such that the pointers are sequential. 
  1287. A `Next' or `Previous' pointer points to any preceding or following node,
  1288. regardless of its hierarchical level."
  1289.  
  1290.         (texinfo-check-for-node-name)
  1291.         (texinfo-delete-existing-pointers)
  1292.         (message 
  1293.          "Sequentially updating node: %s ... " (texinfo-copy-node-name))
  1294.         (save-restriction
  1295.           (widen)
  1296.           (let*
  1297.               ((case-fold-search t)
  1298.                (level (texinfo-hierarchic-level)))
  1299.             (if (string-equal level "top")
  1300.                 (texinfo-top-pointer-case)
  1301.               ;; else
  1302.               (texinfo-sequentially-insert-pointer level 'next)
  1303.               (texinfo-sequentially-insert-pointer level 'previous)
  1304.               (texinfo-sequentially-insert-pointer level 'up)
  1305.               (texinfo-clean-up-node-line)))))
  1306.  
  1307. (defun texinfo-sequentially-find-pointer (level direction)
  1308.   "Find next or previous pointer sequentially in Texinfo file, or up pointer.
  1309. Move point to section associated with the pointer.  Find point even if
  1310. it is in a different section.
  1311.  
  1312. Return type of pointer (either 'normal or 'no-pointer).
  1313.  
  1314. The first argument is a string specifying the general kind of section
  1315. such as \"chapter\ or \"section\".  The section found will be at the
  1316. same hierarchical level in the Texinfo file, or, in the case of the up
  1317. pointer, some level higher.  The second argument (one of 'next,
  1318. 'previous, or 'up) specifies whether to find the `Next', `Previous',
  1319. or `Up' pointer."
  1320.   
  1321.   (cond ((eq direction 'next)
  1322.          (forward-line 3)             ; skip over current node
  1323.          (if (re-search-forward 
  1324.               texinfo-section-types-regexp
  1325.               (point-max)
  1326.               t)
  1327.              'normal
  1328.            'no-pointer))
  1329.         ((eq direction 'previous)
  1330.          (if (re-search-backward 
  1331.               texinfo-section-types-regexp
  1332.               (point-min)
  1333.               t)
  1334.              'normal
  1335.            'no-pointer))
  1336.         ((eq direction 'up)
  1337.          (if (re-search-backward
  1338.               (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
  1339.               beginning
  1340.               t)
  1341.              'normal
  1342.            'no-pointer))
  1343.         (t
  1344.          (error "texinfo-sequential-find-pointer: lack proper arguments"))))
  1345.  
  1346. (defun texinfo-sequentially-insert-pointer (level direction)
  1347.   "Insert the `Next', `Previous' or `Up' node name at point.
  1348. Move point forward.  
  1349.  
  1350. The first argument is the hierarchical level of the Texinfo file, a
  1351. string such as \"section\".  The second argument is direction, one of
  1352. `next, `previous, or 'up."
  1353.  
  1354.   (end-of-line)
  1355.   (insert
  1356.    ", "
  1357.    (save-excursion
  1358.      (texinfo-pointer-name
  1359.       (texinfo-sequentially-find-pointer level direction)))))
  1360.  
  1361.  
  1362. ;;; Inserting `@node' lines
  1363. ; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
  1364. ; before the `@chapter', `@section', and such like lines of a region
  1365. ; in a Texinfo file.
  1366.  
  1367. (defun texinfo-insert-node-lines (beginning end &optional title-p)
  1368.   "Insert missing `@node' lines in region of Texinfo file.
  1369. Non-nil argument (prefix, if interactive) means also to insert the
  1370. section titles as node names; and also to insert the section titles as
  1371. node names in pre-existing @node lines that lack names."
  1372.   (interactive "r\nP")
  1373.  
  1374.   ;; Use marker; after inserting node lines, leave point at end of
  1375.   ;; region and mark at beginning.
  1376.  
  1377.   (let (beginning-marker end-marker title last-section-position)
  1378.  
  1379.     ;; Save current position on mark ring and set mark to end.
  1380.     (push-mark end t)                   
  1381.     (setq end-marker (mark-marker))        
  1382.  
  1383.     (goto-char beginning)
  1384.     (while (re-search-forward
  1385.             texinfo-section-types-regexp 
  1386.             end-marker
  1387.             'end)
  1388.       ;; Copy title if desired.
  1389.       (if title-p
  1390.           (progn 
  1391.             (beginning-of-line)
  1392.             (forward-word 1)
  1393.             (skip-chars-forward " \t")
  1394.             (setq title (buffer-substring
  1395.                          (point)
  1396.                          (save-excursion (end-of-line) (point))))))
  1397.       ;; Insert node line if necessary.
  1398.       (if (re-search-backward
  1399.            "^@node" 
  1400.            ;; Avoid finding previous node line if node lines are close.
  1401.            (or last-section-position    
  1402.                (save-excursion (forward-line -2) (point))) t)
  1403.           ;;  @node is present, and point at beginning of that line
  1404.           (forward-word 1)          ; Leave point just after @node.
  1405.         ;; Else @node missing; insert one.
  1406.         (beginning-of-line)         ; Beginning of `@section' line.
  1407.         (insert "@node\n")
  1408.         (backward-char 1))          ; Leave point just after `@node'.
  1409.       ;; Insert title if desired.
  1410.       (if title-p
  1411.           (progn
  1412.             (skip-chars-forward " \t")
  1413.             ;; Use regexp based on what info looks for
  1414.             ;; (alternatively, use "[a-zA-Z]+");
  1415.             ;; this means we only insert a title if none exists.
  1416.             (if (not (looking-at "[^,\t\n ]+")) 
  1417.                 (progn
  1418.                   (beginning-of-line) 
  1419.                   (forward-word 1)
  1420.                   (insert " " title)
  1421.                   (message "Inserted title %s ... " title)))))
  1422.       ;; Go forward beyond current section title.
  1423.       (re-search-forward texinfo-section-types-regexp 
  1424.                          (save-excursion (forward-line 3) (point)) t)
  1425.       (setq last-section-position (point))
  1426.       (forward-line 1))
  1427.  
  1428.     ;; Leave point at end of region, mark at beginning.
  1429.     (set-mark beginning)
  1430.  
  1431.     (if title-p
  1432.       (message
  1433.        "Done inserting node lines and titles.  You may save the buffer.")
  1434.     (message "Done inserting node lines.  You may save the buffer."))))
  1435.  
  1436.  
  1437. ;;; Update and create menus for multi-file Texinfo sources
  1438.  
  1439. ;;  1. M-x texinfo-multiple-files-update 
  1440. ;;
  1441. ;;     Read the include file list of an outer Texinfo file and
  1442. ;;     update all highest level nodes in the files listed and insert a
  1443. ;;     main menu in the outer file after its top node.
  1444.  
  1445. ;;  2. C-u M-x texinfo-multiple-files-update 
  1446. ;;
  1447. ;;     Same as 1, but insert a master menu.  (Saves reupdating lower
  1448. ;;     level menus and nodes.)  This command simply reads every menu,
  1449. ;;     so if the menus are wrong, the master menu will be wrong.
  1450. ;;     Similarly, if the lower level node pointers are wrong, they
  1451. ;;     will stay wrong.
  1452.  
  1453. ;;  3. C-u 2 M-x texinfo-multiple-files-update 
  1454. ;;
  1455. ;;     Read the include file list of an outer Texinfo file and
  1456. ;;     update all nodes and menus in the files listed and insert a
  1457. ;;     master menu in the outer file after its top node.
  1458.  
  1459. ;;; Note: these functions:
  1460. ;;;
  1461. ;;;   * Do not save or delete any buffers.  You may fill up your memory.
  1462. ;;;   * Do not handle any pre-existing nodes in outer file.  
  1463. ;;;     Hence, you may need a file for indices.
  1464.  
  1465.  
  1466. ;;; Auxiliary functions for multiple file updating
  1467.  
  1468. (defun texinfo-multi-file-included-list (outer-file)
  1469.   "Return a list of the included files in OUTER-FILE."
  1470.   (let ((included-file-list (list outer-file))
  1471.         start)
  1472.     (save-excursion
  1473.       (switch-to-buffer (find-file-noselect outer-file))
  1474.       (widen)
  1475.       (goto-char (point-min))
  1476.       (while (re-search-forward "^@include" nil t)
  1477.         (skip-chars-forward " \t")
  1478.         (setq start (point))
  1479.         (end-of-line)
  1480.         (skip-chars-backward " \t")   
  1481.         (setq included-file-list
  1482.               (cons (buffer-substring start (point))
  1483.                     included-file-list)))
  1484.       (nreverse included-file-list))))
  1485.  
  1486. (defun texinfo-copy-next-section-title ()
  1487.   "Return the name of the immediately following section as a string.
  1488.  
  1489. Start with point at the beginning of the node line.  Leave point at the
  1490. same place.  If there is no title, returns an empty string."
  1491.  
  1492.   (save-excursion
  1493.     (end-of-line)
  1494.     (let ((section-end (or 
  1495.                         (save-excursion
  1496.                           (if (re-search-forward "\\(^@node\\)" nil t)
  1497.                               (match-beginning 0)))
  1498.                         (point-max))))
  1499.       (if (re-search-forward texinfo-section-types-regexp section-end t)
  1500.           (beginning-of-line)
  1501.           ;; copy title
  1502.           (let ((title
  1503.                  (buffer-substring
  1504.                   (progn (forward-word 1)           ; skip over section type
  1505.                          (skip-chars-forward " \t") ; and over spaces
  1506.                          (point))
  1507.                   (progn (end-of-line) (point)))))
  1508.             title)
  1509.         ""))))
  1510.  
  1511. (defun texinfo-multi-file-update (files &optional update-everything)
  1512.   "Update first node pointers in each file in FILES.
  1513. Return a list of the node names and the title immediate following them.
  1514.  
  1515. The first file in the list is an outer file; the remaining are
  1516. files included in the outer file with `@include' commands.
  1517.  
  1518. If optional arg UPDATE-EVERYTHING non-nil, update every menu and
  1519. pointer in each of the included files.
  1520.  
  1521. Also update the `Top' level node pointers of the outer file.
  1522.  
  1523. Requirements:
  1524.  
  1525.   * the first file in the FILES list must be the outer file,
  1526.   * each of the included files must contain exactly one highest
  1527.     hierarchical level node, 
  1528.   * this node must be the first node in the included file,
  1529.   * each highest hierarchical level node must be of the same type.
  1530.  
  1531. Thus, normally, each included file contains one, and only one,
  1532. chapter.
  1533.  
  1534. The menu-list has the form:
  1535.  
  1536.     \(\(\"node-name1\" . \"title1\"\) 
  1537.       \(\"node-name2\" . \"title2\"\) ... \)
  1538.  
  1539. However, there does not need to be a title field."
  1540.   
  1541.   (let (menu-list)
  1542.     
  1543.     ;; Find the name of the first node of the first included file.
  1544.     (switch-to-buffer (find-file-noselect (car (cdr files))))
  1545.     (widen)
  1546.     (goto-char (point-min))
  1547.     (if (not (re-search-forward "^@node" nil t))
  1548.         (error "No `@node' line found in %s !" (buffer-name)))
  1549.     (beginning-of-line)
  1550.     (texinfo-check-for-node-name)
  1551.     (setq next-node-name (texinfo-copy-node-name))
  1552.     
  1553.     (setq menu-list
  1554.           (cons (cons 
  1555.                  next-node-name
  1556.                  (texinfo-copy-next-section-title))
  1557.                 menu-list))
  1558.     
  1559.     ;; Go to outer file
  1560.     (switch-to-buffer (find-file-noselect (car files)))
  1561.     (goto-char (point-min))
  1562.     (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
  1563.         (error "This buffer needs a Top node!"))
  1564.     (beginning-of-line)
  1565.     (texinfo-delete-existing-pointers)
  1566.     (end-of-line)
  1567.     (insert ", " next-node-name ", (dir), (dir)")
  1568.     (beginning-of-line)
  1569.     (setq previous-node-name "Top")
  1570.     (setq files (cdr files))
  1571.     
  1572.     (while files
  1573.       
  1574.       (if (not (cdr files))
  1575.           ;; No next file
  1576.           (setq next-node-name "")
  1577.         ;; Else,
  1578.         ;; find the name of the first node in the next file.
  1579.         (switch-to-buffer (find-file-noselect (car (cdr files))))
  1580.         (widen)
  1581.         (goto-char (point-min))
  1582.         (if (not (re-search-forward "^@node" nil t))
  1583.             (error "No `@node' line found in %s !" (buffer-name)))
  1584.         (beginning-of-line)
  1585.         (texinfo-check-for-node-name)
  1586.         (setq next-node-name (texinfo-copy-node-name))
  1587.         (setq menu-list
  1588.               (cons (cons 
  1589.                      next-node-name
  1590.                      (texinfo-copy-next-section-title))
  1591.                     menu-list)))
  1592.  
  1593.       ;; Go to node to be updated.
  1594.       (switch-to-buffer (find-file-noselect (car files)))
  1595.       (goto-char (point-min))
  1596.       (if (not (re-search-forward "^@node" nil t))
  1597.           (error "No `@node' line found in %s !" (buffer-name)))
  1598.       (beginning-of-line)
  1599.       (texinfo-delete-existing-pointers)
  1600.       (end-of-line)
  1601.       (insert ", " next-node-name ", " previous-node-name ", " up-node-name)
  1602.       
  1603.       (beginning-of-line)
  1604.       (setq previous-node-name (texinfo-copy-node-name))
  1605.       
  1606.       ;; Update other menus and nodes if requested.
  1607.       (if update-everything (texinfo-all-menus-update t))
  1608.       
  1609.       (setq files (cdr files)))
  1610.     (nreverse menu-list)))
  1611.  
  1612. (defun texinfo-multi-files-insert-main-menu (menu-list)
  1613.   "Insert formatted main menu at point.
  1614. Indents the first line of the description, if any, to the value of
  1615. texinfo-column-for-description."
  1616.  
  1617.   (insert "@menu\n")
  1618.   (while menu-list
  1619.     (if (cdr (car menu-list))       ; menu-list has description entry
  1620.         (progn
  1621.           (insert 
  1622.            (format "* %s::" (car (car menu-list)))) ; node-name entry
  1623.           (indent-to texinfo-column-for-description 2)
  1624.           (insert 
  1625.            (format "%s\n" (cdr (car menu-list)))))  ; description entry
  1626.         ;; else menu-list lacks description entry
  1627.       (insert
  1628.        (format "* %s::\n" (car (car menu-list)))))  ; node-name entry
  1629.     (setq menu-list (cdr menu-list)))
  1630.   (insert "@end menu"))
  1631.  
  1632.  
  1633. (defun texinfo-multi-file-master-menu-list (files-list)
  1634.   "Return master menu list from files in FILES-LIST.
  1635. Menu entries in each file collected using `texinfo-master-menu-list'.
  1636.  
  1637. The first file in FILES-LIST must be the outer file; the others must
  1638. be the files included within it.  A main menu must already exist."
  1639.   (save-excursion
  1640.     (let (master-menu-list)
  1641.       (while files-list
  1642.         (switch-to-buffer (find-file-noselect (car files-list)))
  1643.         (message "Working on: %s " (current-buffer))
  1644.         (goto-char (point-min))
  1645.         (setq master-menu-list
  1646.               (append master-menu-list (texinfo-master-menu-list)))
  1647.         (setq files-list (cdr files-list)))
  1648.       master-menu-list)))
  1649.  
  1650.  
  1651. ;;; The multiple-file update function
  1652.  
  1653. (defun texinfo-multiple-files-update
  1654.   (outer-file &optional update-everything make-master-menu)
  1655.   "Update first node pointers in each file included in OUTER-FILE;
  1656. create or update main menu in the outer file that refers to such nodes. 
  1657. This does not create or update menus or pointers within the included files.
  1658.  
  1659. With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
  1660. insert a master menu in OUTER-FILE.  This does not create or update
  1661. menus or pointers within the included files.
  1662.  
  1663. With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
  1664. interactive), update all the menus and all the `Next', `Previous', and
  1665. `Up' pointers of all the files included in OUTER-FILE before inserting
  1666. a master menu in OUTER-FILE.
  1667.  
  1668. The command also updates the `Top' level node pointers of OUTER-FILE.
  1669.  
  1670. Notes: 
  1671.  
  1672.   * this command does NOT save any files--you must save the
  1673.     outer file and any modified, included files.
  1674.  
  1675.   * except for the `Top' node, this command does NOT handle any
  1676.     pre-existing nodes in the outer file; hence, indices must be
  1677.     enclosed in an included file.
  1678.  
  1679. Requirements:
  1680.  
  1681.   * each of the included files must contain exactly one highest
  1682.     hierarchical level node, 
  1683.   * this highest node must be the first node in the included file,
  1684.   * each highest hierarchical level node must be of the same type.
  1685.  
  1686. Thus, normally, each included file contains one, and only one,
  1687. chapter."
  1688.  
  1689.   (interactive "fName of outer `include' file: ")
  1690.  
  1691.   (cond (current-prefix-arg
  1692.          (setq make-master-menu (listp current-prefix-arg))
  1693.          (setq update-everything (numberp current-prefix-arg))))
  1694.  
  1695.   (let* ((included-file-list (texinfo-multi-file-included-list outer-file))
  1696.          (files included-file-list)
  1697.          main-menu-list
  1698.          next-node-name
  1699.          previous-node-name
  1700.          (up-node-name "Top"))
  1701.  
  1702. ;;; Update the pointers 
  1703. ;;; and collect the names of the nodes and titles
  1704.     (setq main-menu-list (texinfo-multi-file-update files update-everything))
  1705.  
  1706. ;;; Insert main menu
  1707.  
  1708.   ;; Go to outer file
  1709.   (switch-to-buffer (find-file-noselect (car included-file-list)))
  1710.   (if (texinfo-old-menu-p
  1711.        (point-min)
  1712.        (save-excursion
  1713.          (re-search-forward "^@include")
  1714.          (beginning-of-line)
  1715.          (point)))
  1716.  
  1717.       ;; If found, leave point after word `menu' on the `@menu' line.
  1718.       (progn
  1719.         (texinfo-incorporate-descriptions main-menu-list)
  1720.         ;; Delete existing menu.
  1721.         (beginning-of-line)
  1722.         (delete-region
  1723.          (point)
  1724.          (save-excursion (re-search-forward "^@end menu") (point)))
  1725.         ;; Insert main menu
  1726.         (texinfo-multi-files-insert-main-menu main-menu-list))
  1727.  
  1728.     ;; Else no current menu; insert it before `@include'
  1729.     (texinfo-multi-files-insert-main-menu main-menu-list))
  1730.  
  1731. ;;; Insert master menu
  1732.  
  1733.   (if make-master-menu
  1734.       (progn
  1735.         ;; First, removing detailed part of any pre-existing master menu
  1736.         (goto-char (point-min))
  1737.         (if (re-search-forward texinfo-master-menu-header nil t)
  1738.             ;; Remove detailed master menu listing
  1739.             (progn
  1740.               (goto-char (match-beginning 0))
  1741.               (let ((end-of-detailed-menu-descriptions
  1742.                      (save-excursion     ; beginning of end menu line
  1743.                        (goto-char (texinfo-menu-end))
  1744.                        (beginning-of-line) (forward-char -1)
  1745.                        (point))))
  1746.                 (delete-region (point) end-of-detailed-menu-descriptions))))
  1747.  
  1748.         ;; Create a master menu and insert it
  1749.         (texinfo-insert-master-menu-list 
  1750.          (texinfo-multi-file-master-menu-list 
  1751.           included-file-list)))))
  1752.   (message "Multiple files updated."))
  1753.  
  1754.  
  1755. ;;; Place `provide' at end of file.
  1756. (provide 'texnfo-upd)
  1757. ;;;;;;;;;;;;;;;; end texnfo-upd.el ;;;;;;;;;;;;;;;;
  1758.